def ip2long(ip):
    ips = ip.split(".")
    return (int(ips[0]) << 24) \
            + (int(ips[1]) << 16) \
            + (int(ips[2]) << 8) \
            + (int(ips[3]))

def long2ip(ip):
    return str(((0b11111111 << 24) & ip) >> 24) + "." \
            + str(((0b11111111 << 16) & ip) >> 16) + "." \
            + str(((0b11111111 << 8) & ip) >> 8) + "." \
            + str(0b11111111 & ip)

print ip2long("192.168.1.1")
print long2ip(ip2long("192.168.1.1"))
